package com.voice.client.auth;

import com.voice.client.auth.handle.AppKeyAuthHandler;
import com.voice.client.auth.handle.DeviceAuthHandler;
import com.voice.client.Profile;
import com.voice.core.exception.ClientException;
import java.util.Map;

public class AuthenticationFactory {

    public static AuthHandler getAuthHandler(Profile profile) {
        Map<String, String> params = profile.getAuthParams();
        if (params != null && !params.isEmpty()) {
            String authType = profile.getAuthParams().get("name");
            if ("deviceKey".equals(authType)) {
                return new DeviceAuthHandler(params);
            } else if ("appKey".equals(authType)) {
                return new AppKeyAuthHandler(params);
            } else {
                throw new ClientException("unsupported auth type: " + authType);
            }
        } else {
            throw new ClientException("authorization parameter is empty");
        }
    }

}
